home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 8285 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.5 KB  |  66 lines

  1. Path: csun.edu!hbmus009
  2. From: hbmus009@csun.edu (christopher johnson)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: What dose a DLL file do?
  5. Date: 2 Mar 1996 21:58:39 GMT
  6. Organization: California State University, Northridge
  7. Message-ID: <4hagaf$9id@dewey.csun.edu>
  8. References: <4h8b73$7ua@coranto.ucs.mun.ca>
  9. NNTP-Posting-Host: louie.csun.edu
  10. X-Newsreader: TIN [version 1.2 PL2]
  11.  
  12. Matthew Smyth (ybf1037@InfoNET.st-johns.nf.ca) wrote:
  13. >     I was wondering what exactly dose a DLL file do?
  14.  
  15. DLL stands for Dynamic Link Library.  These are a special kind of library
  16. that doesn't get statically linked into your programs.  The final linking
  17. process happens when you execute a program that will make use of a
  18. particular DLL.  Ok, that didn't make a lot of sense to anyone that
  19. doesn't know what a DLL is in the first place.  Let me try again.
  20.  
  21. A DLL is a collection of functions (a library).  Lets have an example dll
  22. with one exported function say,
  23.  
  24.      int FAR PASCAL _export nSucc(int n)
  25.  
  26. Which returns the value n + 1.  I'll draw a picture:
  27.  
  28. example.dll
  29. +-------------------------------------+
  30. |                                     |
  31. | int FAR PASCAL _export nSucc(int n) |
  32. |                                     |
  33. +-------------------------------------+
  34.  
  35. Ok, now you have a program where you want to make use of this function
  36. nSucc().  To do so, you include the header file (probably something like
  37. example.h).  Then you link your program to the EXPORT library of
  38. example.dll (not the actual library itself).  A copy of the function
  39. nSucc() doesn't get included in your compiled code.  What does get included
  40. is a set of instructions telling the program to at runtime load
  41. example.dll and use the nSucc function in that module.  So we might write
  42.  
  43.     #include "example.h"
  44.  
  45.     main()
  46.     {
  47.       int n;
  48.       
  49.       for (n = 0; n < 5; n = nSucc(n))  /* Makes a call to example.dll */
  50.         printf("This program does nothing useful.\n");
  51.     }
  52.  
  53. That is why when you try to run something like Netscape and you don't have
  54. a copy of winsock.dll, it gives you that error message.  Netscape trys to
  55. load winsock.dll at runtime, and if it can't do so, all of the calls to
  56. functions inside of winsock.dll will create General Protection Faults. 
  57. Therefore it aborts the program.
  58.  
  59. So why would you want to use a DLL?  Lots o reasons, but someone else
  60. should perhaps have a go at answering that.  God knows I've cacked this
  61. explanation up enough.
  62.  
  63.                             Chris Johnson
  64.                             hbmus009@csun.edu
  65.  
  66.